#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import logging


class Logger:
    def __init__(self, log_file, log_name, cmd_level=logging.INFO, file_level=logging.INFO):
        self.logger = logging.getLogger(log_name)
        self.logger.setLevel(logging.DEBUG)
        log_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

        # 设置文件日志
        fh = logging.FileHandler(log_file)
        fh.setFormatter(log_formatter)
        fh.setLevel(file_level)

        # 设置控制台日志
        sh = logging.StreamHandler()
        sh.setFormatter(log_formatter)
        sh.setLevel(cmd_level)

        # 给logger添加handler
        self.logger.addHandler(fh)
        self.logger.addHandler(sh)

    def debug(self, message):
        self.logger.debug(message)

    def info(self, message):
        self.logger.info(message)

    def warn(self, message):
        self.logger.warning(message)

    def error(self, message):
        self.logger.error(message)

    def critical(self, message):
        self.logger.critical(message)

# if __name__ == "__main__":
#     logger = Logger('logging.log')
#     logger.debug("debug")
#     logger.info('info')
#     logger.warn('warning')
#     logger.error('error')
#     logger.critical('critical')
